#include "downloadfiledialog.h"

#include <QDebug>

DownloadFileDialog::DownloadFileDialog(QWidget *parent)
	: QDialog(parent)
	, ui(new Ui::DownloadFileDialogClass())
{
	ui->setupUi(this);
	init();
}

void  DownloadFileDialog::init() {
	connect(ui->downBtn, &QPushButton::clicked, this, &DownloadFileDialog::onDownloadBtnClick);
	connect(ui->cancelBtn, &QPushButton::clicked, this, &DownloadFileDialog::onCancelBtnClick);
	connect(ui->flushBtn, &QPushButton::clicked, this, &DownloadFileDialog::onFlushBtnClick);
}

void DownloadFileDialog::setFileTree(Json::Value& root)
{
	ui->fileTree->clear();
	// 将root保存的文件树展示在QTreeWidget中

}


void DownloadFileDialog::onDownloadBtnClick() {
	QString downloadPath =  QFileDialog::getExistingDirectory(nullptr, "download", "选择文件夹");
	if (downloadPath == "") {
		this->done(static_cast<int>(DownLoadType::CANCEL));
	}
	else {
		// 跳过signal设置文件下载路径
		emit sigSetDownloadPath(downloadPath);
		this->done(static_cast<int>(DownLoadType::DOWNLOAD));
	}
}

void DownloadFileDialog::onCancelBtnClick() {
	this->done(static_cast<int>(DownLoadType::CANCEL));
}

void DownloadFileDialog::onFlushBtnClick() {
	emit this->sigFlushFileTree();
}



DownloadFileDialog::~DownloadFileDialog()
{
	delete ui;
}
